const { Router } = require('express')
const express = require('express')
//路由容器
const collection = express.Router()
const axios = require('axios')
const { JsonWebTokenError } = require('jsonwebtoken')
const jwt = require("jsonwebtoken")
collection.get('/collection/queryAllCollection', (req, res) => {
   axios({
        method:'get',
        url : '/collection/queryAllCollection',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            token:req.session.token
        },
        params:{
            userId:jwt.decode(req.session.token).id
        }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
       console.log(jwt.decode(req.session.token).id)
       res.status(500).json({
           msg:err
       })
   })
})
collection.delete('/collection/deleteSomeCollection', (req, res) => {
    console.log(req.query)
    let {collectionId}=req.query
    let delId='';
    for(let key of collectionId){
        if(delId == ''){
            delId = delId + key
            console.log(delId)
            console.log(req.query)
        }else{
            delId = delId +',' + key;
            console.log(delId)
            console.log(req.query)
        }
    }
   axios({
        method:'delete',
        url : '/collection/deleteSomeCollection',
        params:{
            collectionId:delId
        }
   }).then(function(data){
       res.status(200).json({
           data:data.data,
           code:0
       })
   }).catch(function(err){
       res.status(500).json({
           msg:err
       })
   })
})
module.exports=collection;